package com.jiankangjin.appspos.services.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import com.jiankangjin.appspos.services.ReportServices;
import com.jiankangjin.appspos.vo.GetReportResultVo;
import com.jiankangjin.appspos.vo.SearchReportVo;

@Service
public class ReportServicesImpl implements ReportServices{
	private static final transient Log logger = LogFactory.getLog(ReportServicesImpl.class);
	
	/**
	 * 查询报表
	 */
	@Override
	public SearchReportVo searchReport(String token, String dateBegin,
			String dateEnd, String searchWord) {
		SearchReportVo searchReportVo = new SearchReportVo();	
		try {	
			searchReportVo.setResp_status("0000");
			searchReportVo.setResult_quantity(4);
			searchReportVo.setResult_id("214161881720090");
			searchReportVo.setSign("searchReport-sign");
			return searchReportVo;
		} catch (Exception e) {
			logger.error(this, e);
			return searchReportVo;
		}
		
//		try {
//			HashMap<String, Object> params = new HashMap<>();
//			params.put("token",token);
//			params.put("order_date_begin", dateBegin);
//			params.put("order_date_end", dateEnd);
//			params.put("search_word", searchWord);
//			params.put("sign", "appSPOS_searchReport_sign");
//			if (logger.isInfoEnabled()) {
//				logger.info("调交易系统查询报表:" + params);
//			}
//			Map<String, Object> map = HttpClient.getInstance()
//					.doPOSTgetHashMap("/transSystem/search_report", params);
//			if(map == null) {
//				searchReportVo.setResp_status("9999");
//				searchReportVo.setMsg("调交易系统查询报表返回空");
//				return searchReportVo;
//			}
//			String[] resTip = ResourceMap.getArray("T_search_report_" + (String) map.get("status"));
//			searchReportVo.setResp_status(resTip[0]);
//			searchReportVo.setMsg(resTip[1]);
//			searchReportVo.setResult_id((String)map.get("result_id"));
//			searchReportVo.setResult_quantity(Integer.parseInt((String) map.get("result_quantity")));
//			searchReportVo.setSign("appSPOS_searchReport_sign");
//			return searchReportVo;
//		} catch (Exception e) {
//			logger.error(this, e);
//			return searchReportVo;
//		}
	}

	/**
	 * 查询报表结果
	 */
	@Override
	public GetReportResultVo getReportResult(String token, String resultId,
			int page, int quantity) {
		GetReportResultVo getReportResultVo = new GetReportResultVo();
		try {
			GetReportResultVo.Report report1 = getReportResultVo.new Report();
			report1.setDate("2014-10-8");
			report1.setName("上海医院1号");
			report1.setUrl("http://payment-test.jiankangjin.com/report/report_exmple_20141112.xlsx");
			GetReportResultVo.Report report2 = getReportResultVo.new Report();
			report2.setDate("2014-11-11");
			report2.setName("上海医院2号");
			report2.setUrl("http://payment-test.jiankangjin.com/report/report_exmple_20141112.xlsx");
			GetReportResultVo.Report report3 = getReportResultVo.new Report();
			report3.setDate("2014-11-12");
			report3.setName("上海医院3号");
			report3.setUrl("http://payment-test.jiankangjin.com/report/report_exmple_20141112.xlsx");
			GetReportResultVo.Report report4 = getReportResultVo.new Report();
			report4.setDate("2014-11-13");
			report4.setName("上海医院4号");
			report4.setUrl("http://payment-test.jiankangjin.com/report/report_exmple_20141112.xlsx");
			List<GetReportResultVo.Report> report = new ArrayList<>();
			report.add(report1);
			report.add(report2);
			report.add(report3);
			report.add(report4);
			getReportResultVo.setResp_status("0000");
			getReportResultVo.setReport(report);
			getReportResultVo.setReport_quantity(4);
			getReportResultVo.setSign("getReportResult-sign");
			return getReportResultVo;
		} catch (Exception e) {
			logger.error(this, e);
			return getReportResultVo;
		}
		
//		try {
//			HashMap<String, Object> params = new HashMap<>();
//			params.put("token",token);
//			params.put("result_id", resultId);
//			params.put("page", page);
//			params.put("quantity", quantity);
//			params.put("sign", "appSPOS_getReportResult_sign");
//			if (logger.isInfoEnabled()) {
//				logger.info("调交易系统查询报表结果:" + params);
//			}
//			Map<String, Object> map = HttpClient.getInstance()
//					.doPOSTgetHashMap("/transSystem/get_report_result", params);
//			if(map == null) {
//				getReportResultVo.setResp_status("9999");
//				getReportResultVo.setMsg("交易系统查询报表结果返回空");
//				return getReportResultVo;
//			}
//			String[] resTip = ResourceMap.getArray("T_get_report_result_" + (String) map.get("status"));
//			getReportResultVo.setResp_status(resTip[0]);
//			getReportResultVo.setMsg(resTip[1]);
//			getReportResultVo.setReport(map.get("report"));
//			getReportResultVo.setReport_quantity(Integer.parseInt((String)map.get("report_quantity")));
//			getReportResultVo.setSign("appSPOS_getReportResult_sign");
//			return getReportResultVo;
//		} catch (Exception e) {
//			logger.error(this, e);
//			return getReportResultVo;
//		}
	}
}
